package com.web;

import com.domain.UserActPlanActivity;
import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
 * 客户查看自己的活动数据
 * 接收 /LoginUser 的 userId数据
 * 提交到 userService 的 AllUaPa 函数
 * 转发到 /userSelfAct.jsp 页面进行展示
 */
@WebServlet("/ShowUserSelf")//显示客户自己的活动数据
public class ShowUserSelfServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //解决乱码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //1.获取客户的id
        String id = request.getParameter("userId");
        System.out.println("userId = " + id+" 在查询参加的活动");

        //2.获取用户的所有活动
        userService userService = new userService();
        List<UserActPlanActivity> userActPlanActivities = userService.AllUaPa(Integer.parseInt(id));

        //3.进行重定向,转到客户活动展示页面/userShowAct.jsp进行展示
        request.setAttribute("userList",userActPlanActivities);//存入数据
        request.getRequestDispatcher("/userSelfAct.jsp").forward(request,response);//进行转发

    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
